﻿$(document).ready(function () {
    var currentDate = new Date();
    $("#year").append("<option value='" + (currentDate.getFullYear() - 2) + "'>" + (currentDate.getFullYear() - 2) + "</option>")
    .append("<option value='" + (currentDate.getFullYear() - 1) + "'>" + (currentDate.getFullYear() - 1) + "</option>")
    .append("<option value='" + currentDate.getFullYear() + "' selected>" + currentDate.getFullYear() + "</option>");
    $("#reissueYear").append("<option value='" + (currentDate.getFullYear() - 2) + "'>" + (currentDate.getFullYear() - 2) + "</option>")
    .append("<option value='" + (currentDate.getFullYear() - 1) + "'>" + (currentDate.getFullYear() - 1) + "</option>")
    .append("<option value='" + currentDate.getFullYear() + "' selected>" + currentDate.getFullYear() + "</option>");
    for (var i = 1; i < 13; i++) {
        var selectstr = "";
        if (i == currentDate.getMonth()) selectstr = "selected";
        $("#month").append("<option value='" + i + "' " + selectstr + ">" + i + "月</option>");
        $("#reissueMonth").append("<option value='" + i + "' "+selectstr+">" + i + "月</option>");
    }
    var id = getPar1("id");
    if (id != "") {
        $("#year").val(instance[0].year);
        $("#month").val(instance[0].month);
        $("#reissueYear").val(instance[0].reissueYear);
        $("#reissueMonth").val(instance[0].reissueMonth);
    }
    $("#empCode").change(function () {
        $("#deptName").val("");
        $("#postName").val("");
        $("#txtEmployeeId").val("");
        $("#EmployeeId").val("");
        var empcode = $("#empCode").val();
        if (empcode == "") return;
        instance[0].Flag = 0;
        var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=EmployeeCode='" + empcode + "'&r=" + Math.random();
        $.get(url, function (d, s) {
            var list = eval("(" + d + ")");
            if (list.total > 0) {
                for (var o in list.rows) {
                    var empId = list.rows[o].ID;
                    var empName = list.rows[o].CName;
                    var dept = list.rows[o].DeptName;
                    var post = list.rows[o].PostName;
                    if (typeof (empcode) != "undefined") {
                        $("#deptName").val(dept);
                        $("#postName").val(post);
                        $("#txtEmployeeID").val(empName);
                        $("#EmployeeId").val(empId);
                        break;
                    }
                }
            }
        });
    });
    var employeeCode = getPar1("empcode");
    //修改时，隐藏选择按钮，并且工号不可编辑
    if (employeeCode != "") {
        $("#empCode").val(employeeCode).attr("readonly", true).css("background", "whitesmoke").trigger("change");
        $("#btnEmployeeId").hide();
    }
});

//数据验证
var fnCheckData = function () {

}

//自定义数据保存
var fnCustomSave = function () {
    var id = getPar1("id");
    var url = encodeURI("../EHR/hrSalaryAjax.aspx?flag=savereissuesalary&id=" + id + "&empId=" + instance[0].EmployeeId + "&salary=" + instance[0].reissueSum + "&year=" + instance[0].year + "&month=" + instance[0].month + "&reissueYear=" + instance[0].reissueYear + "&reissueMonth=" + instance[0].reissueMonth + "&des=" + instance[0].Des + "&r=" + Math.random());
    YAHOO.util.Connect.asyncRequest('POST', url, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {
                    alert("数据保存成功！");
                }
                else {
                    alert("数据保存失败！");
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);
}

function ValueChanged() {
    var empId = $("#EmployeeId").val();
    //alert(empId);
    //获取员工编号
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'&r=" + Math.random();
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total > 0) {
            for (var o in list.rows) {
                var empcode = list.rows[o].EmployeeCode;
                var dept = list.rows[o].DeptName;
                var post = list.rows[o].PostName;
                if (typeof (empcode) != "undefined") {
                    $("#deptName").val(dept);
                    $("#postName").val(post);
                    $("#empCode").val(empcode);
                    break;
                }
            }
        }
    });
}